package com.example.rocketmq.demo;

import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class ProducerController {
    @Value("${rocketmq.producer.customized-trace-topic}")
    private String topicName;

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @GetMapping("send")
    public void send(String msg){
        /**
         * sea 订阅主题 topic
         * msg 发送的数据
         */
        // rocketMQTemplate.convertAndSend("sea",msg);
        SendResult sendResult = rocketMQTemplate.syncSend(topicName, msg);
        System.out.println(sendResult.getSendStatus());
        rocketMQTemplate.asyncSend(topicName, msg, new SendCallback() {
            @Override
            public void onSuccess(SendResult sendResult) {

            }

            @Override
            public void onException(Throwable throwable) {

            }
        });
    }

}

